import { reqGoodsDetailInfo } from "@/api";

const state = {
    goodsDetails: {},
};

const getters = {
    categoryView(state) {
        return state.goodsDetails.categoryView || {};
    },
    skuInfo(state) {
        return state.goodsDetails.skuInfo || {};
    },
    spuSaleAttrList(state) {
        return state.goodsDetails.spuSaleAttrList || {};
    },
    skuImageList(state) {
        return state.goodsDetails.skuInfo?.skuImageList || [];
    },
};

const actions = {
    async getGoodsDetails({ commit }, skuId) {
        const result = await reqGoodsDetailInfo(skuId);
        commit("RECEIVE_GOODS_DETAILS", { goodsDetails: result });
    },
};

const mutations = {
    RECEIVE_GOODS_DETAILS(state, { goodsDetails }) {
        state.goodsDetails = goodsDetails;
    },
};

export default {
    namespaced: true,
    state,
    getters,
    actions,
    mutations,
};
